#include <stdio.h>
#include "sc.h"
#include "timer.h"
#define TRIALS 10
PixelToPixelOp()
p2p_1(in stream unsigned char *i,
      out stream unsigned char *o)
{
  int ii;
  unsigned char t = *i;

  for (ii=0; ii < 1; ii++)
    t = sqrt(t)*sqrt(t);

  *o = t;
}

PixelToPixelOp()
p2p_2(in stream unsigned char *i,
      out stream unsigned char *o)
{
  int ii;
  unsigned char t = *i;

  for (ii=0; ii < 2; ii++)
    t = sqrt(t)*sqrt(t);

  *o = t;
}

PixelToPixelOp()
p2p_3(in stream unsigned char *i,
      out stream unsigned char *o)
{
  int ii;
  unsigned char t = *i;

  for (ii=0; ii < 4; ii++)
    t = sqrt(t)*sqrt(t);

  *o = t;
}

ReductionOp()
sum(in stream unsigned char *i, in int *prevval, out int *outval)
{
  *outval = *i + *prevval;
}

MAINTYPE MAIN(int argc, char **argv)
{
  int *a;
  int val, i;

  scInit(argc, argv);
  _setbuffersize(1048580);


  for (i=0; i < TRIALS; i++)
  {
    generate(scint(1024), a);

    p2p_2(a, a);
    p2p_2(a, a);
    sum(a, scint(0), &val);
    _block(&val);
    val = val / 1048576;
    generate(scint(1023), a);
    if (i%2)
    {
      p2p_1(a, a);
      p2p_3(a, a);
    }

    discard(a);
  }

  return scExit();
}
